package com.flower.auth.controller;

import com.flower.auth.common.entity.Result;
import com.flower.auth.convert.AuthRoleDTOConverter;
import com.flower.auth.convert.AuthUserDTOConverter;
import com.flower.auth.dto.AuthRoleDTO;
import com.flower.auth.dto.AuthUserDTO;
import com.flower.domain.entity.AuthRoleBO;
import com.flower.domain.entity.AuthUserBO;
import com.flower.domain.service.AuthRoleDomainService;
import com.flower.domain.service.AuthUserDomainService;
import com.google.common.base.Preconditions;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author lavender
 * @version 1.0
 * @date 2024-07-17 12:22
 */
@RestController
@RequestMapping("/role/")
public class RoleController {

    @Resource
    private AuthRoleDomainService authRoleDomainService;

    @RequestMapping("add")
    public Result<Boolean> add(@RequestBody AuthRoleDTO authRoleDTO){


        AuthRoleBO authRoleBO = AuthRoleDTOConverter.INSTANCE.convertDTOToBO(authRoleDTO);


        Boolean register = authRoleDomainService.register(authRoleBO);


        return Result.ok(register);
    }

    @RequestMapping("update")
    public Result<Boolean> update(@RequestBody AuthRoleDTO authRoleDTO){


        AuthRoleBO authRoleBO = AuthRoleDTOConverter.INSTANCE.convertDTOToBO(authRoleDTO);

        Boolean update = authRoleDomainService.update(authRoleBO);

        return Result.ok(update);
    }


    @RequestMapping("delete")
    public Result<Boolean> delete(@RequestBody AuthRoleDTO authRoleDTO){


        AuthRoleBO authRoleBO = AuthRoleDTOConverter.INSTANCE.convertDTOToBO(authRoleDTO);

        Boolean delete = authRoleDomainService.delete(authRoleBO);

        return Result.ok(delete);
    }
}
